#include <iostream>
using namespace std;

const int MAXSIZE=100;

class Heap {
	
public:
	void insert(const int x);
	int deleteMin();
	void buildHeap(int n);
	Heap(){
		size=0;
		for(int i=0;i<MAXSIZE;++i)
			data[i]=0;
	}
	void print(){
		for(int i=1;i<=size;++i)
			cout<<data[i]<<endl;
	}
private:
	void percolateDown(int n);
	int size;
	int data[MAXSIZE];
};


void Heap::insert(const int x)
{
	int hole = ++size;
	while(hole>1 && data[hole/2]>x){
		data[hole]=data[hole/2];
		hole /= 2;
	}
	data[hole]=x;
}

int Heap::deleteMin(){
	if(size==0)
		return 0;d
	int min=data[1];
	data[1]=data[size--];
	percolateDown(1);
	return min;
}

void Heap::percolateDown(int n)
{
	if(n>size||n<1)
		return;
	int x=data[
	n];
	while(2*n <= size){
		int child=2*n;
		if(child < size && data[child+1]<data[child])
			child++;
		if(data[child]<data[n])
			data[n]=data[child];
		else
			break;
		n=child;
	}
	data[n]=x;
}

int main()
{
	Heap p;
	p.insert(10);
	p.insert(8);
	p.insert(12);
	p.insert(6);
	p.insert(7);
	
	
	p.print();
	cout<<"!!!"<<p.deleteMin()<<endl;
	p.print();
	return 0;
}
